<?php
/**
 * ShopEx licence
 *
 * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)
 * @license  http://ecos.shopex.cn/ ShopEx License
 */

class b2c_ctl_site_product extends b2c_frontpage{

    var $_call = 'call';
    var $type = 'goods';
    var $seoTag = array('shopname','brand','goods_name','goods_cat','goods_intro','goods_brief','brand_kw','goods_kw','goods_price','update_time','goods_bn');
    function __construct($app){
        parent::__construct($app);
        $shopname = $app->getConf('system.shopname');
        if(isset($shopname)){
            $this->title = app::get('b2c')->_('商品页_').$shopname;
            $this->keywords = app::get('b2c')->_('商品页_').$shopname;
            $this->description = app::get('b2c')->_('商品页_').$shopname;
        }

    }

    public function get_goods_spec() {
        $gid = $this->_request->get_get('gid');
        if( !$gid ) {
            echo '';
            exit;
        }
        $this->pagedata['goodshtml']['name'] = kernel::single("b2c_goods_detail_name")->show( $gid,$arrGoods );
        if( $arrGoods['spec'] && is_array($arrGoods['spec']) )  {
            foreach( $arrGoods['spec'] as $row ) {
                $option = $row['option'];
                if( $option && is_array($option) ) {
                    foreach( $option as $img ) {
                        foreach( (array)explode(',',$img['spec_goods_images']) as $imageid )
                            $return[$imageid] = base_storager::image_path($imageid,'s');
                    }
                }
            }
        }
        $this->pagedata['spec2image'] = json_encode( $return );

        $imageDefault = app::get('image')->getConf('image.set');
        $this->pagedata['defaultImage'] = $imageDefault['S']['default_image'];

        $arrGoods['spec2image'] = json_encode($return);
        $this->pagedata['goods'] = $arrGoods;
        $this->pagedata['goodshtml']['spec'] = kernel::single("b2c_goods_detail_spec")->show( $gid,$arrGoods );
        $imageDefault = app::get('image')->getConf('image.set');
        $this->pagedata['image_default_id'] = $imageDefault['S']['default_image'];
        $this->pagedata['goodshtml']['button'] = kernel::single('b2c_goods_detail_button')->show( $gid,$arrGoods );
		$this->page( 'site/gallery/spec_dialog.html',true );

	}

    function call(){
        $args = func_get_args();
        $action = array_shift($args);
        if(method_exists($this,$action)){
            call_user_func_array(array(&$this,$action),$args);
        }else{
            $objSchema = &$this->app->model('goods/schema');
            $gid = array_shift($args);
            if(!is_int($gid)) {
                echo 'Invalid Schema calling';
                die();
            }
            $objSchema->runFunc($gid,$action,$args);
        }
    }

    function getVirtualCatById($cat_id=0){
        $vobjCat = &$this->app->model('goods/virtualcat');
        $xml = &$this->app->model('utility/xml');
        $result=$vobjCat->getVirtualCatById(intval($cat_id));

        $searchtools = &$this->app->model('goods/search');
        foreach($result as $k=>$v){
            $filter=$vobjCat->_mkFilter($result[$k]['filter']);
            $cat_id=$filter['cat_id'];
            $filter=$searchtools->encode($filter);
            $result[$k]['url']=$this->system->mkUrl('gallery',$this->app->getConf('gallery.default_view'),array(implode(',',$cat_id),$filter,'0','','',$result[$k]['virtual_cat_id']));
        }
        echo json_encode($result);
    }
    public function index() {  //$gid,$specImg='',$spec_id=''
        $objProduct = &$this->app->model('products');

        $_getParams = $this->_request->get_params();
//        $params = $this->_request->get_post():
        $gid = $_getParams[0];
        $specImg = $_getParams[1];
        $spec_id = $_getParams[2];
        $this->id = $gid;
        $this->customer_source_type='product';
        $this->customer_template_type='product';
        $this->customer_template_id=$gid;
//        $member_lv = intval($this->system->request['member_lv']);

        $objGoods = &$this->app->model('goods');
        $GLOBALS['runtime']['path'] = $objGoods->getPath($gid,'');

        $aGoods = kernel::single('b2c_goods_model')->getGoods( $gid );
        $siteMember = $this->get_current_member();
        $this->site_member_lv_id = $siteMember['member_lv'];
        $this->pagedata['this_member_lv_id'] = $this->site_member_lv_id;
        if(!$aGoods){
            echo  app::get('b2c')->_('无效商品');exit;
        }
        $blocks = array('promotion'=>array('goods_id'=>$aGoods['goods_id']));
        foreach(kernel::servicelist('b2c_site_goods_detail_block') as $object){
            $promotionMsg = $object->get_blocks($blocks);   //todo check is right?
        }
        $objSales = $this->app->model('sales_rule_order');
        $pOrderList = $objSales->getList('name',array('status'=>'true','from_time|lthan'=>time(),'to_time|than'=>time()));
        foreach($pOrderList as $pk=>$pv){
            $promotionOrder .= ' '.$pv['name'];
        }
       $tTitle=(empty($aGoods['seo']['seo_title']) ? $aGoods['name'] : $aGoods['seo']['seo_title']).(empty($aCat['cat_name'])?"":" - ".$aCat['cat_name']);
        if(empty($this->title)) $this->title = $tTitle;

       if(is_array($aGoods['spec'])){
              foreach($aGoods['spec'] as $sv){
               $specValue[] = $sv['spec_name'];
              }
       }
       $this->pagedata['specShowItems'] =$specValue;

        /*--------------*/
        if (is_array($gImages)&&count($gImages)>0){
            $this->pagedata['images']['gimages'] = $gImages;
        }
        $this->pagedata['goods'] = $aGoods;

        if ($this->pagedata['goods']['product']){
            $priceArea = array();

            if ($_COOKIE['MLV'])
                $MLV = $_COOKIE['MLV'];
            else{
                $level=&$this->app->model('member_lv');
                $MLV=$level->get_default_lv();
            }
            if ($MLV){
                foreach($this->pagedata['goods']['product'] as $gpk => $gpv){
                   $priceArea[]=$gpv['price']['price']['current_price'];//销售价区域
                   $mktpriceArea[]=$gpv['price']['mktprice']['price'];//市场价区域
                }
                if (count($priceArea)>1){
                    $minprice = min($priceArea);
                    $maxprice = max($priceArea);
                    if ($minprice<>$maxprice){
                        $this->pagedata['goods']['minprice'] = $minprice;
                        $this->pagedata['goods']['maxprice'] = $maxprice;
                    }
                }
                if (count($mktpriceArea)>1){
                    $mktminprice = min($mktpriceArea);
                    $mktmaxprice = max($mktpriceArea);
                    if ($mktminprice<>$mktmaxprice){
                        $this->pagedata['goods']['minmktprice'] = $mktminprice;
                        $this->pagedata['goods']['maxmktprice'] = $mktmaxprice;

                    }
                }
            }
          //计算货品冻结库存总和
            foreach($this->pagedata['goods']['product'] as $key => $val){
                $totalFreez += $val['freez'];
            }

        }
        else{
            $totalFreez = $this->pagedata['goods']['freez'];
        }
        $oMlv = $this->app->model('member_lv');
        $mLevelList = $oMlv->getList('*','',0,-1);
        $this->pagedata['mLevel'] = $mLevelList;
        $aData = $this->get_current_member();
        if(!$aData['member_id']){
            $this->pagedata['login'] = 'nologin';
        }
###############
/**** begin 商品评论 ****/
        $objComment = kernel::single('b2c_message_disask');
        $aComment = $objComment->good_all_disask($gid);
        /**** begin 相关商品 ****/
        $aLinkId['goods_id'] = array();
        foreach($objGoods->getLinkList($gid) as $rows){
            if($rows['goods_1']==$gid) $aLinkId['goods_id'][] = $rows['goods_2'];
            else $aLinkId['goods_id'][] = $rows['goods_1'];
        }
        if(count($aLinkId['goods_id'])>0){
            $aLinkId['marketable'] = 'true';
            $this->pagedata['goods']['link'] = $objGoods->getList('*',$aLinkId,0,500);
            $this->pagedata['goods']['link_count'] = count($aLinkId['goods_id']);
        }

        $oGoodsLv = &$this->app->model('goods_lv_price');

        $oMlv = &$this->app->model('member_lv');
        $mlv = $oMlv->db_dump( $this->site_member_lv_id,'dis_count' );
        if(is_array($this->pagedata['goods']['link'])){
            foreach ($this->pagedata['goods']['link'] as $key=>&$val) {
                $temp = $objProduct->getList('product_id, spec_info, price, freez, store,   marketable, goods_id',array('goods_id'=>$val['goods_id'],'marketable'=>'true'));
                if( $this->site_member_lv_id ){
                    $tmpGoods = array();
                    foreach( $oGoodsLv->getList( 'product_id,price',array('goods_id'=>$val['goods_id'],'level_id'=>$this->site_member_lv_id ) ) as $k => $v ){
                        $tmpGoods[$v['product_id']] = $v['price'];
                    }
                    foreach( $temp as &$tv ){
                        $tv['price'] = (isset( $tmpGoods[$tv['product_id']] )?$tmpGoods[$tv['product_id']]:( $mlv['dis_count']*$tv['price'] ));
                    }
                    $val['price'] = $tv['price'];
                }
                $this->pagedata['goods']['link'][$key]['spec_desc_info'] = $temp;
                $this->pagedata['goods']['link'][$key]['product_id'] = $temp[0]['product_id'];
            }
        }
        /**** end 相关商品 ****/

// 评分类型
        $comment_goods_type = $this->app->model('comment_goods_type');
        if(!($comment_goods_type->getList('*'))){
            $sdf['type_id'] = 1;
            $sdf['name'] = app::get('b2c')->_('综合评分');
            $addon['is_total_point'] = 'on';
            $sdf['addon'] = serialize($addon);
            $comment_goods_type->insert($sdf);
        }
        $this->pagedata['comment_goods_type'] = $comment_goods_type->getList('*');
        $this->pagedata['point_status'] =  app::get('b2c')->getConf('goods.point.status') ? app::get('b2c')->getConf('goods.point.status'): 'on';
        $this->pagedata['base_setting'] = $objComment->get_basic_setting();
        $gask_type = unserialize($this->app->getConf('gask_type'));
        if($gask_type){
            foreach($gask_type as $key => $val){
                $gask_type[$key]['total'] = $objComment->get_ask_total($gid,$val['type_id'],'ask');
            }
            $this->pagedata['gask_type'] = $gask_type;
        }
        $objPoint = $this->app->model('comment_goods_point');
        $this->pagedata['goods_point'] = $objPoint->get_single_point($gid);
        $this->pagedata['_all_point'] = $objPoint->get_goods_point($gid);
        $this->pagedata['comment'] = $aComment;

        /**** end 商品评论 ****/
#####################################
        $cur = app::get('ectools')->model('currency');
        $this->pagedata['readingGlass'] = $this->app->getConf('site.reading_glass');
        $this->pagedata['readingGlassWidth'] = $this->app->getConf('site.reading_glass_width');
        $this->pagedata['readingGlassHeight'] = $this->app->getConf('site.reading_glass_height');
        $this->pagedata['goods']['product_freez'] = $totalFreez;
        $this->pagedata['promotionMsg'] = $promotionMsg;
        if($this->app->getConf('site.promotion.display') == 'true')
            $this->pagedata['promotionOrder'] = $promotionOrder;
        $this->pagedata['sellLog'] = $sellLogSetting;
        $this->pagedata['sellLogList'] = $sellLogList;

        $ret = $cur->getFormat($this->app->getConf('site.currency.defalt_currency'));
        $ret =array(
            'decimals'=>$this->app->getConf('system.money.decimals'),
            'dec_point'=>$this->app->getConf('system.money.dec_point'),
            'thousands_sep'=>$this->app->getConf('system.money.thousands_sep'),
            'fonttend_decimal_type'=>$this->app->getConf('system.money.operation.carryset'),
            'fonttend_decimal_remain'=>$this->app->getConf('system.money.decimals'),
            'sign' => $ret['sign']
        );

        $this->pagedata['goods']['setting']['score'] = $this->app->getConf('site.get_policy.method');
        $this->pagedata['money_format'] = json_encode($ret);
        $this->pagedata['askshow'] = $this->app->getConf('comment.verifyCode.ask');
        $this->pagedata['goodsBnShow'] = $this->app->getConf('goodsbn.display.switch');
        $this->pagedata['discussshow'] = $this->app->getConf('comment.verifyCode.discuss');
        $this->pagedata['showStorage'] = $this->app->getConf('site.show_storage');
        $this->pagedata['specimagewidth'] = $this->app->getConf('spec.image.width');
        $this->pagedata['specimageheight'] = $this->app->getConf('spec.image.height');
        $this->pagedata['goodsRecommend'] = $this->app->getConf('goods.recommend');
        $this->pagedata['goodsproplink'] = 1;
        //$this->pagedata['goodsproplink'] = $this->app->getConf('goodsprop.display.switch');
  //      $this->getGlobal($this->seoTag,$this->pagedata);

        $GLOBALS['pageinfo']['goods'] = &$GLOBALS['runtime']['goods_name'];
        $GLOBALS['pageinfo']['brand'] = &$GLOBALS['runtime']['brand'];
        $GLOBALS['pageinfo']['gcat'] = &$GLOBALS['runtime']['goods_cat'];
        if( !$aGoods['images'] ){
            $imageDefault = app::get('image')->getConf('image.set');
            $this->pagedata['goods']['images'][]['image_id'] = $imageDefault['M']['default_image'];
            $this->pagedata['goods']['image_default_id'] = $imageDefault['M']['default_image'];
        }
        /*else{
            foreach($aGoods['images'] as $key=>$val){
                if(isset($val['image_id'])){
                     $this->pagedata['goods']['image_default_id'] = $val['image_id'];
                }
            }
        }*/

        $this->pagedata['spec_default_pic'] = $this->app->getConf('spec.default.pic');
        $this->setSeo('site_product','index',$this->prepareSeoData($this->pagedata));

        if( is_string($aGoods['seo_info']) ){
            $aGoods['seo_info'] = unserialize( $aGoods['seo_info'] );
        }
        if( $aGoods['seo_info']['seo_title'] ){
            $this->title = $aGoods['seo_info']['seo_title'];
        }
        if( $aGoods['seo_info']['seo_keywords'] ){
            $this->keywords = $aGoods['seo_info']['seo_keywords'];
        }
        if( $aGoods['seo_info']['seo_description'] ){
            $this->description = $aGoods['seo_info']['seo_description'];
        }
        $this->set_tmpl('product');

        ////////////////////////////////////////////////////////////////////
        //  页面内容 body servicelist 按钮下 edit by jiaolei
        ///////////////////////////////////////////////////////////////////
        $this->pagedata['info_page_list'] = $this->_get_servicelist_by('b2c_products_index_info');


        ////////////////////////////////////////////////////////////////////
        //  页面按钮servicelist 加入购物车 立即购买等 可扩展  edit by jiaolei
        ///////////////////////////////////////////////////////////////////
        $this->pagedata['btn_page_list'] = $this->_get_servicelist_by('b2c_products_index_btn');


        ////////////////////////////////////////////////////////////////////
        //  页面内容 body servicelist 按钮下  edit by jiaolei
        ///////////////////////////////////////////////////////////////////
        $this->pagedata['body_page_list'] = $this->_get_servicelist_by('b2c_products_index_body');

        $this->page('site/product/index.html');
    }
    function prepareSeoData($data){
        $brief = $this->get_goods_brief($data);
        $goodsCat = $this->get_goods_cat($data);
        return array(
            'goods_name'=>$data['goods']['name'],
            'goods_brand'=>$data['goods']['brand']['brand_name'],
            'goods_bn'=>$data['goods']['bn'],
            'goods_cat'=>$goodsCat,
            'goods_brief'=>$brief,
            'goods_price'=>$data['goods']['price']
        );
    }


    function goodsSpec( $gid = 0,&$aGoods = null ){
        $o = new b2c_goods_detail_spec($this->app);
        echo $o->show( $gid,$aGoods );
    }

       /*
       @author litie@shopex.cn


       $gids like:  2,3,4,5,6,7

       @return like:
       [{"goods_id":"39","thumbnail_pic":"http:\/\/pic.shopex.cn\/pictures\/gimages\/77900fbf8fcc94de.jpg","small_pic":"http:\/\/pic.shopex.cn\/pictures\/gimages\/4d927b00ab29b199.jpg","big_pic":"http:\/\/pic.shopex.cn\/pictures\/gimages\/389e97389f1616f7.jpg"},{"goods_id":"42","thumbnail_pic":"http:\/\/pic.shopex.cn\/pictures\/gimages\/54d1c53bc455244f.jpg","small_pic":"http:\/\/pic.shopex.cn\/pictures\/gimages\/9dce731f131aab5e.jpg","big_pic":"http:\/\/pic.shopex.cn\/pictures\/gimages\/ac4420118e680927.jpg"}]
    */
    function picsJson(){
        $gids = explode(',',$_GET['gids']);

        if(!$gids)return '';
        $o = $this->app->model('goods');
        $imageDefault = app::get('image')->getConf('image.set');

        $data = $o->db_dump(current($gids),'image_default_id');
        if( !$data['image_default_id'] ){
            $data = base_storager::image_path( $imageDefault['S']['default_image'],'s' );
        }else{
            $img = base_storager::image_path($data['image_default_id'],'s' );
            if( $img )
                $data = $img;
            else
                $data = base_storager::image_path( $imageDefault['S']['default_image'],'s' );
        }
        echo json_encode($data);
        exit;
    }

     function diff(){

        $this->_response->set_header('Cache-Control', 'no-store');
        $imageDefault = app::get('image')->getConf('image.set');
        $comare=explode("|",$_COOKIE['S']['GCOMPARE']);

        foreach($comare as $ci){
           $ci = stripslashes($ci);
           $ci = json_decode($ci,true);
           $gids[] = $ci['gid'];
        }

        $oGoods = &$this->app->model('goods');
         $aData = $this->get_current_member();
        if(!$aData['member_id']){
            $this->pagedata['login'] = 'nologin';
        }

        $this->pagedata['diff'] = $oGoods->diff($gids);

        foreach($this->pagedata['diff']['goods'] as $key=>$row){
             $this->pagedata['diff']['goods'][$key]['defaultImage'] = $imageDefault['S']['default_image'];
             $goods_name[] = $row['name'];
        }
        if(is_array($goods_name))
            $this->pagedata['goods']['name'] = implode(',',$goods_name);

        $objProduct = $this->app->model('products');
        $oGoodsLv = &$this->app->model('goods_lv_price');
        $siteMember = $this->get_current_member();
        $this->site_member_lv_id = $siteMember['member_lv'];
        $oMlv = &$this->app->model('member_lv');
        $mlv = $oMlv->db_dump( $this->site_member_lv_id,'dis_count' );
        foreach ($this->pagedata['diff']['goods'] as $key=>&$val) {
            $temp = $objProduct->getList('product_id, spec_info, price, freez, store,   marketable, goods_id',array('goods_id'=>$val['goods_id'],'marketable'=>'true'));
            if( $this->site_member_lv_id ){
                $tmpGoods = array();
                foreach( $oGoodsLv->getList( 'product_id,price',array('goods_id'=>$val['goods_id'],'level_id'=>$this->site_member_lv_id ) ) as $k => $v ){
                    $tmpGoods[$v['product_id']] = $v['price'];
                }
                foreach( $temp as &$tv ){
                    $tv['price'] = (isset( $tmpGoods[$tv['product_id']] )?$tmpGoods[$tv['product_id']]:( $mlv['dis_count']*$tv['price'] ));
                }
                $val['price'] = $tv['price'];
            }
            $this->pagedata['diff']['goods'][$key]['spec_desc_info'] = $temp;
            $this->pagedata['diff']['goods'][$key]['product_id'] = $temp[0]['product_id'];
        }
        $imageDefault = app::get('image')->getConf('image.set');
        $this->pagedata['image_set'] = $imageDefault;
        $this->pagedata['defaultImage'] = $imageDefault['S']['default_image'];
        
        
        $setting['buytarget'] = $this->app->getConf('site.buy.target');
        $this->pagedata['setting'] = $setting;
            
        $this->page('site/product/diff.html');
    }


    function viewpic($goodsid, $selected='def'){
        $objGoods = &$this->app->model('goods');
        $o = &app::get('image')->model('image_attach');
        $dImg = $o->getList('*',array('target_id'=>$goodsid));
        $aGoods = $objGoods->dump($goodsid,'name');
        $this->pagedata['goods_name'] = urlencode(htmlspecialchars($aGoods['name'],ENT_QUOTES));
        $this->pagedata['goods_name_show'] = $aGoods['name'];
        $this->pagedata['company_name'] = str_replace("'","&apos;",htmlspecialchars($this->app->getConf('system.shopname')));
        if(!$dImg){
        $imageDefault = app::get('image')->getConf('image.set');
            $dImg[]['image_id'] = $imageDefault['L']['image_id'];
            /*
            $selected=0;
            $id=rand(0,10);
            $dImg[$id]=array(
                'gimage_id'=>$id,
                'goods_id'=>$goodsid,
                'small'=>($this->app->getConf('site.default_small_pic')),
                'big'=>($this->app->getConf('site.default_big_pic')),
                'thumbnail'=>($this->app->getConf('site.default_thumbnail_pic'))
            );*/
        }

        $this->pagedata['image_file'] = $dImg;
        if($selected=='def'){
            $selected=current($dImg);
            $selected=$selected['target_id'];
        }
        $this->pagedata['selected'] = $selected;
        $this->page('site/product/viewpic.html',true);

    }


    function photo(){
    }

    function pic(){
    }

    function gnotify($goods_id=0,$product=0){
        if($_POST['goods']['goods_id']){
            $goods_id = $_POST['goods']['goods_id'];
            $product_id = $_POST['goods']['product_id'];
        }
        $this->id =$goods_id;
        $objGoods = &$this->app->model('goods');
        $aProduct = $objGoods->getProducts($goods_id, $product_id);
        $this->pagedata['goods'] = $aProduct[0];
        if($this->member[member_id]){
            #$objMember = &$this->system->loadModel('member/member');
            #$aMemInfo = $objMember->getFieldById($this->member[member_id], array('email'));
            $this->pagedata['member'] = $aMemInfo;
        }

        $this->page('site/product/gnotify.html');
    }

    function toNotify(){
        if(!$_POST['item'][0]['goods_id'] || !$_POST['item'][0]['product_id']){
            $this->splash('failed', 'back', app::get('b2c')->_('参数错误'));
        }
        $objProducts = &$this->app->Model('products');
        $ret = $objProducts->getList('product_id',array('product_id' => $_POST['item'][0]['product_id'],'goods_id' => $_POST['item'][0]['goods_id']));
        if(!$ret) $this->splash('failed', 'back', app::get('b2c')->_('参数错误'));
        $back_url = app::get('site')->base_url(1);
        $member_goods = $this->app->model('member_goods');
        if($member_goods->check_gnotify($_POST)){
            $this->splash('failed','back',app::get('b2c')->_('不能重复登记'));
        }
        else{
            $member_data = $this->get_current_member();
            if($member_goods->add_gnotify($member_data['member_id']?$member_data['member_id']:null,$_POST['item'][0]['goods_id'],$_POST['item'][0]['product_id'],$_POST['email'])){
            $this->splash('success',$back_url,app::get('b2c')->_('登记成功'));
        }
        else{
           $this->splash('failed','back',app::get('b2c')->_('登记失败'));
        }
          }
        /*
        $this->begin($this->app->mkUrl("index"));
        $this->_verifyMember(false);
        $aTemp = array();
        $oNotify = $this->app->model('member_goods');
        if(!ereg("^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+",$_POST['email']))
                $this->end(false, __('邮箱格式错误'));
        else{
                foreach($_POST['item'] as $key=>$val){

                    $aTemp['goods_id'] = $val['goods_id'];
                    $aTemp['product_id'] = $val['product_id'];
                    $aTemp['member_id'] = isset($this->member['member_id']) && $this->member['member_id'] != ''?$this->member['member_id']:0;
                    $aTemp['email'] = $_POST['email']!=''? $_POST['email'] : $this->member['email'];
                    $aTemp['creat_time'] = time();

                    $oNotify->add_gnotify($aTemp);
                }

                $this->end(true, __('提交成功'));

        }*/
    }

    function goodspics($goodsId,$images=array(),$imgGstr=''){
        $Goods=&$this->app->model('goods/gimage');
        $objGoods = &$this->app->model('trading/goods');
        $gimg=$_POST['gimages'];
        $goodsId=$_POST['goodsId'];
        if ($gimg){
            $tmpGimg=explode(",",$_POST['gimages']);
            if ($tmpGimg){
                foreach($tmpGimg as $key => $val){
                    if (!$val)
                        unset($tmpGimg[$key]);
                }
                $tmpImage=$Goods->get_by_gimage_id($goodsId,$tmpGimg);
            }
            $this->pagedata['imgtype'] = 'spec';
       }
        else{
            $tmpImage = $Goods->get_by_goods_id($goodsId);
        }
        $this->pagedata['images']['gimages']=$tmpImage;
        $this->pagedata['goods'] = $objGoods->getGoods($goodsId);
        $this->__tmpl='product/goodspics.html';
        $this->output();
    }

    function get_brand($result){
        return $result['goods']['brand'];
    }
    function get_goods_name($result){
        return $result['goods']['name'];
    }
    function get_goods_bn($result){
        return $result['goods']['bn'];
    }
    function get_goods_cat($result){
        $pcat=$this->app->model('goods_cat');
        $row=$pcat->dump($result['goods']['category']['cat_id'],'cat_name');
        return $row['cat_name'];
    }
    function get_goods_intro($result){
        $intro= strip_tags($result['goods']['intro']);
        if (strlen($intro)>50)
            $intro=substr($intro,0,50);
        return $intro;
    }
    function get_goods_brief($result){
        $brief= strip_tags($result['goods']['brief']);
        //$brief=preg_split('/(<[^<>]+>)/',$result['goods']['brief'],-1);
        if (strlen($brief)>50)
            $brief=substr($brief,0,50);
        return $brief;
    }
    function get_brand_kw($result){
        $brand=$this->app->model('goods/brand');
        $row=$brand->instance($result['goods']['brand_id'],'brand_keywords');
        return $row['brand_keywords'];
    }
    function get_goods_kw($result){
        /*
        $goods=$this->app->model('trading/goods');
        $row=$goods->getKeywords($result['goods']['goods_id']);
        if ($row){
            foreach($row as $key => $val){
                $tmpRow[]=$val['keyword'];
            }
            return implode(",",$tmpRow);
        }*/
            return;
    }
    function get_goods_price($result){
        return $result['goods']['price'];
    }
    function get_update_time($result){
        return date("c",$result['goods']['last_modify']);
    }

    function recooemd(){
        $back_url = $this->gen_url(array('app'=>'b2c','ctl'=>'site_product','act'=>'index','arg'=>$_POST['goods_id']));
        $app = app::get('desktop');
        $aTmp['usermail'] = $app->getConf('email.config.usermail');
        $aTmp['smtpport'] = $app->getConf('email.config.smtpport');
        $aTmp['smtpserver'] = $app->getConf('email.config.smtpserver');
        $aTmp['smtpuname'] = $app->getConf('email.config.smtpuname');
        $aTmp['smtppasswd'] = $app->getConf('email.config.smtppasswd');
        $aTmp['sendway'] = $app->getConf('email.config.sendway');
        $aTmp['acceptor'] = $user_email;     //收件人邮箱
        $aTmp['shopname'] = $this->app->getConf('system.shopname');
        $acceptor = $_POST['email'];     //收件人邮箱
        $subject =app::get('b2c')->_("来自[").$_POST['name'].app::get('b2c')->_("]的商品推荐");
        $url = &app::get('site')->router()->gen_url(array('app'=>'b2c','ctl'=>'site_product','full'=>1,'act'=>'index','arg'=>$_POST['goods_id']));
        $body = app::get('b2c')->_("尊敬的客户,您的好友").$_POST['name'].app::get('b2c')->_(',为您推荐了一款商品,请您点击查看').'<a href='.$url.'>'.$_POST['goods_name'].'</a>';
        $email = kernel::single('desktop_email_email');
        if ($email->ready($aTmp)){
        $res = $email->send($acceptor,$subject,$body,$aTmp);
        if ($res) {
            $this->splash('success',$back_url,app::get('b2c')->_('发送成功'));
        }
        else{
           $this->splash('failed',$back_url,app::get('b2c')->_('发送失败,请联系管理员'));
        }
      }
      else{
          $this->splash('failed',$back_url,app::get('b2c')->_('发送失败,请联系管理员'));
      }
    }


    //////////////////////////////////////////////////////////////////////////
    // 返回servicelist
    // @param servicelist名称
    ///////////////////////////////////////////////////////////////////////////
    private function _get_servicelist_by($servicelist)
    {
        if( !$servicelist ) return false;
        $list = array();
        foreach( kernel::servicelist($servicelist) as $object ) {
            if( !$object ) continue;
            $index = null;
            if( !$object->file ) continue; //模板文件 没有直接跳过
            if( method_exists($object,'get_order') )
                $index = $object->get_order();

            while(true) {
                if( !isset($list[$index]) ) break;
                $index++;
            }
            $path = explode('_',get_class($object));
            $list[$index] = array(
                                'file' => $object->file,
                                'app'  => $object->_app ? $object->_app : $path[0],
                            );

            if( method_exists($object,'set_page_data') ) {
                $object->set_page_data($this->customer_template_id,$this);//设置html内容
            }
        }
        krsort($list);
        return $list;
    }

    function cron($goods_id){
        kernel::single('b2c_goods_crontab')->run($goods_id);
    }
    
}
